package edu.gyc.collectionhomework;

import java.util.HashSet;
import java.util.Objects;

public class Human {
    private int id;
    private String name;
    private String  address;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Human(int id, String name, String address) {
        this.id = id;
        this.name = name;
        this.address = address;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                '}';
    }

    public static void main(String[] args) {
        HashSet<Human> hs = new HashSet<Human>();
        hs.add(new Human(111,"张三", "贵州"));
        hs.add(new Human(222,"张三", "广东"));
        hs.add(new Human(333,"李四", "广西"));
        hs.add(new Human(333,"李四", "广东"));
        System.out.println(hs.size()); //4
        System.out.println(hs);
    }

    @Override
    public boolean equals(Object o) {
        System.out.println("called equals");
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Human human = (Human) o;
        return id == human.id && name.equals(human.name) ;
    }

    @Override
    public int hashCode() {
        System.out.println("called hashcode");
        return Objects.hash(id, name,address);
    }
}
